package com.itheima.mobilesafe69.receiver;

import com.itheima.mobilesafe69.utils.ConstantValue;
import com.itheima.mobilesafe69.utils.PrefUtils;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;

public class BootReceiver extends BroadcastReceiver {
	private static final String tag = null;

	@Override
	public void onReceive(Context context, Intent intent) {
		//一旦监听到开机广播,就需要去发送短信给指定号码
		Log.i(tag, "接收到了开关机的广播,可在此处做sim卡是否切换的判断...............");
		
		//1,获取本地存储的sim卡序列号
		String spSimSerialNumber = PrefUtils.getString(context,ConstantValue.SIM_SERIAL_NUMBER, "");
		//2,获取当前插入手机的sim卡序列号(TelephoneMananger)
		TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		String simSerialNumber = tm.getSimSerialNumber()+"xxx";
		//3,两个sim卡序列号比对
		if(!spSimSerialNumber.equals(simSerialNumber)){
			//4,如果序列号不一致,则给指定联系人发送短信(发送短信权限)
			SmsManager sm = SmsManager.getDefault();
			String phone = PrefUtils.getString(context,ConstantValue.CONTACT_PHONE, "");
			if(!TextUtils.isEmpty(phone)){
				sm.sendTextMessage(phone, null, "sim change!!!!", null, null);
			}
		}
	}
}
